package com.lwm.controller;

import com.github.pagehelper.PageInfo;
import com.lwm.domain.EarlyWarning;
import com.lwm.domain.ProjectMaintain;
import com.lwm.domain.ResponseResult;
import com.lwm.service.ProjectMaintainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 项目维护控制层
 */
@RestController
@RequestMapping("/projectMaintain")
@Slf4j
public class ProjectMaintainController {

    @Resource
    private ProjectMaintainService projectMaintainService;

    /**
     * 保存
     *
     * @param projectMaintain 项目维护实体类
     * @return {@link ResponseResult}<{@link Object}>
     */
    @PostMapping
    public ResponseResult<Object> save(@RequestBody ProjectMaintain projectMaintain) {
        return projectMaintainService.save(projectMaintain);
    }

    /**
     * 删除
     *
     * @param ids id集合
     * @return {@link ResponseResult}<{@link Object}>
     */
    @DeleteMapping
    public ResponseResult<Object> remove(@RequestBody List<Long> ids) {
        return projectMaintainService.remove(ids);
    }

    /**
     * 编辑
     *
     * @param projectMaintain 项目维护实体类
     * @return {@link ResponseResult}<{@link Object}>
     */
    @PutMapping
    public ResponseResult<Object> edit(@RequestBody ProjectMaintain projectMaintain) {
        return projectMaintainService.edit(projectMaintain);
    }

    /**
     * 分页
     *
     * @param projectMaintain 项目维护实体类(条件查询参数封装)
     * @param page            页码
     * @param size            数量
     * @return {@link ResponseResult}<{@link PageInfo}<{@link EarlyWarning}>>
     */
    @GetMapping("/page")
    public ResponseResult<PageInfo<ProjectMaintain>> page(Integer page, Integer size, ProjectMaintain projectMaintain) {
        log.info("分页参数 projectMaintain {}", projectMaintain);
        return projectMaintainService.page(page, size, projectMaintain);
    }

    /**
     * 根据id获取
     *
     * @param id 项目id
     * @return {@link ResponseResult}<{@link Object}>
     */
    @GetMapping("/{id}")
    public ResponseResult<Object> getById(@PathVariable Long id) {
        log.info("id {}", id);
        return projectMaintainService.getById(id);
    }
}
